﻿#region Usings

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Web.Mvc;
using Omu.Awesome.Core;
using XPressify.Data.CompliedQueries;
using XPressify.Data.Helpers;
using XPressify.Helpers;
using XPressify.Models;
using XPressify.Data;
using XPressify.Core;
using NotificationType = XPressify.Models.NotificationType;

#endregion

namespace XPressify.Controllers
{
    public class GroupController : SubjectController
    {
        [Authorize]
        public ActionResult GroupOwnerList(int? page)
        {
            var user = CurrentUser;
            var repo = Repository;
            var groups = GroupCompiledQueries.GetAllGroupsOf(repo as Repository, user.Id);
            var groupPageable = groups.GetPageable(page ?? 1, 5, (g => g.Created));

            var groupList = new List<GroupModel>();
            foreach (var @group in groupPageable.Page)
            {
                var model = new GroupModel
                                {
                                    Group = @group,
                                    SubjectId = user.Id,
                                    CurrentUserId = user.Id
                                };
                groupList.Add(model);
            }
            var groupModelPageable = new Pageable<GroupModel> { Page = groupList, PageCount = groupPageable.PageCount, PageIndex = groupPageable.PageIndex };
            return View("GroupList", groupModelPageable);
        }


        [Authorize]
        public ActionResult GroupViewerList(Guid id, int? page)
        {
            var repo = Repository;
            var viewerUser = CurrentUser;
            var ownerUser = UserCompiledQueries.GetUser(repo as Repository, id);
            var groups = GroupCompiledQueries.GetAllPublicGroupsOf(repo as Repository, ownerUser.Id);

            var groupList = new List<GroupModel>();
            foreach (var @group in groups)
            {
                var model = new GroupModel
                {
                    SubjectId = ownerUser.Id,
                    Group = @group,
                    CurrentUserId = viewerUser.Id
                };
                groupList.Add(model);
            }
//            var groupModelPageable = new Pageable<GroupModel> { Page = groupList, PageCount = groupPageable.PageCount, PageIndex = groupPageable.PageIndex };
            return View("GroupViewerList", groupList);
        }


        //
        // GET: /Group/Details/5
        [Authorize]
        public ActionResult GroupDetails(Guid id, Guid? postId)
        {
            var repo = Repository;
            var group = GroupCompiledQueries.GetGroup(repo as Repository, id);
            if (group == null)
            {
                // notify
                var notifyModel = new NotifyModel
                {
                    Title = "XPressify - Group",
                    Header = "Group",
                    Body = "Group does not exist",
                    NotificationType = NotificationType.Notification
                };
                return RedirectToAction("Notify", "Home", notifyModel);
            }
            var administrator = Repository.GetAdminOf(id);

            var user = CurrentUser;
            var administratorBlocked = RelationshipCompiledQueries.IsMember(repo as Repository, user.Id, administrator.Id); // try to find if organizer is one of the blocked user, if so then we not show it
            var isMember = RelationshipCompiledQueries.IsMember(repo as Repository, user.Id, group.Id);

            var wallAlbum = AlbumCompiledQueries.GetWallAlbum(repo as Repository, group.Id);

            //get wall album cover picture
            var coverPicture = MediaCompiledQueries.GetCoverOf(repo as Repository, wallAlbum.Id);
            var wallAlbumSubject = AlbumCompiledQueries.GetAlbumSubject(repo as Repository, wallAlbum.Id);
            var path = "";
            var hasCoverPicture = true; // this is for showing the picture or not if false the cover picture will not show only album name
            if (coverPicture != null)
                path = "/Media/" + wallAlbumSubject.Id + "/" + wallAlbum.Id + "/" + coverPicture.Id + "." + coverPicture.FileType;
            else if (coverPicture == null && wallAlbum.IsProfile == false)
            {
                path = "/Media/Image/DefaultCover.jpg";
                hasCoverPicture = false;
            }

            //get all posts from owner user and put them in dictionary
            var dictionary = new Dictionary<Post, List<Post>>();

            var allPosts = new List<Post>();
            if(postId != null)
            {
                allPosts = PostCompiledQueries.GetAllPostsByPostIdDesc(repo as Repository, postId ?? Guid.Empty).ToList();
            }
            else
            {
                allPosts = PostCompiledQueries.GetAllPostsByPostSubjectIdOfDesc(repo as Repository, group.Id).ToList();
            }
            
            foreach (var post in allPosts)
            {
                var allComments = Repository.GetAllComments(post);
                dictionary.Add(post, allComments);
            }

            var currentUserProfilePicturePath = Repository.GetProfilePicturePath(user.Id);

            var model = new DetailsGroupModel
                            {
                                Name = group.Name,
                                Description = group.Description,
                                Username = group.Username,
                                Created = group.Created,
                                IsAdministrator = administrator.Id == CurrentUser.Id,
                                GroupId = id,
                                AdministratorBlocked = administratorBlocked,
                                Administrator = administrator,
                                IsMemeber = isMember,
                                CurrentUserProfilePicturePath = currentUserProfilePicturePath,
                                AllPosts = dictionary,
                                HasCoverPictureAlbum = hasCoverPicture,
                                WallAlbumCoverPicturePath = path,
                                GroupPrivacyType = group.PrivacyType,
                                WallAlbumId = wallAlbum.Id,
                                CurrentUser = user
                            };
            return View(model);
        }

        //
        // GET: /Group/Create
        [Authorize]
        public ActionResult GroupCreate()
        {
            return View();
        }

        //
        // POST: /Group/Create
        [Authorize]
        [HttpPost]
        public ActionResult GroupCreate(CreateGroupModel model)
        {
            if(ModelState.IsValid)
            {
                try
                {
                    var group = new Group
                    {
                        Id = Guid.NewGuid(),
                        Name = model.Name,
                        Description = "",
                        Username = "",
                        Created = DateTime.Now,
                        Type = SubjectType.Group,
                        PrivacyType = Convert.ToInt16(model.Privacy)
                    };
                    Repository.AddObject(group);
                    Repository.SaveChanges();

                    var relationship = new Relationship
                    {
                        Id = Guid.NewGuid(),
                        Type = ObjectType.Relationship,
                        Created = DateTime.Now,
                        Description = RelationshipType.AdministratorOfText,
                        BaseSubject = CurrentUser,
                        BaseSubject2 = group,
                        Status = RelationshipStatus.Confirmed,
                        RelationType = RelationshipType.AdministratorOf,
                        Name = RelationshipType.AdministratorOfText,
                        PrivacyType = ObjectPrivacy.FriendsOnly
                    };
                    Repository.AddObject(relationship);

                    var groupWallAlbum = new Album()
                    {
                        BaseSubject = group,
                        Created = DateTime.Now,
                        Id = Guid.NewGuid(),
                        IsProfile = false,
                        IsWall = true,
                        Name = "Wall album",
                        Description = "",
                        MediaType = AlbumMediaType.Mix,
                        Type = ObjectType.Album,
                        PrivacyType = ObjectPrivacy.Everyone,
                        Location = ""
                    };
                    Repository.AddObject(groupWallAlbum);

                    var newPostDummy = new Post
                    {
                        BaseObject = groupWallAlbum,
                        BaseSubject = groupWallAlbum.BaseSubject,
                        Content = "",
                        Id = Guid.NewGuid(),
                        Description = "Post dummy - wall album for group",
                        Title = "Post dummy - wall album for group",
                        Type = BaseMessageType.Post,
                        PostType = PostType.PostDummy,
                        Created = DateTime.Now,
                        CommentType = CommentType.PostWithItsComments
                    };
                    Repository.AddObject(newPostDummy);
                    Repository.SaveChanges();

                    //create physical folder
                    var path = Server.MapPath("~/Media/" + group.Id + "/"); // create a event directory
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path); // create directory
                    }
                    path = Server.MapPath("~/Media/" + group.Id + "/" + groupWallAlbum.Id + "/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path); // create directory
                    }


                    return Json(model);
                }
                catch
                {
                    return View(model);
                }
            }
            return View(model);
        }

        //
        // GET: /Group/Edit/5
        [Authorize]
        public ActionResult GroupEdit(Guid id)
        {
            var repo = Repository;
            var group = GroupCompiledQueries.GetGroup(repo as Repository, id);
            var admin = Repository.GetAdminOf(id);
            var user = CurrentUser;
            if(admin == null || admin.Id != user.Id)
            {
                return RedirectToAction("ProfileView", "Profile", new { id = user.Id });
            }
            
            var model = new EditGroupModel
                            {
                                Name = group.Name,
                                GroupId = group.Id,
                                Privacy = Convert.ToString(group.PrivacyType)
                            };
            return View(model);
        }

        //
        // POST: /Group/Edit/5
        [Authorize]
        [HttpPost]
        public ActionResult GroupEdit(Guid id, EditGroupModel model)
        {
            if(ModelState.IsValid)
            {
                try
                {
                    var repo = Repository;
                    var group = GroupCompiledQueries.GetGroup(repo as Repository, id);

                    //put all new values in dictionary key = var name, value = new value // only if they are different so value is changed
                    var changes = new Dictionary<string, string>();
                    if (group.Name != model.Name)
                        changes.Add("name", model.Name);
                    var privacy = Convert.ToInt16(model.Privacy);
                    if (group.PrivacyType != privacy)
                    {
                        var newValueString = privacy == SubjectPrivacy.Public ? "public" : "private";
                        changes.Add("privacy", newValueString);
                    }
                    CreateNotification(group.Id, group.FullName, changes);

                    group.Name = model.Name;
                    group.PrivacyType = Convert.ToInt16(model.Privacy);
                    Repository.SaveChanges();
                    return Json(model);
                }
                catch
                {
                    return View(model);
                }
            }
            return View(model);
        }

     
        [Authorize]
        [HttpPost]
        public ActionResult GroupDelete(DeleteGroupModel model)
        {
            try
            {
                var repo = Repository;
                var group = GroupCompiledQueries.GetGroup(repo as Repository, model.GroupId);
                var admin = Repository.GetAdminOf(model.GroupId);
                var user = CurrentUser;
                if (admin == null || admin.Id != user.Id)
                {
                    return RedirectToAction("ProfileView", "Profile", new { id = user.Id });
                }
                var relationships = RelationshipCompiledQueries.GetAllRelationshipsOf(repo as Repository, group.Id);
                foreach (var relationship in relationships)
                {
                    Repository.DeleteObject(relationship); // delete relationships with group
                }


                var path = Server.MapPath("~/Media/" + group.Id + "/");
                if (Directory.Exists(path))
                {
                    Directory.Delete(path, true); // delete physical directory
                }
                Repository.SaveChanges();
                DeleteAllBaseObjects(group.Id);
                Repository.DeleteObject(group);
                Repository.SaveChanges();

                return RedirectToAction("GroupOwnerList");
            }
            catch
            {
                return View(model);
            }
        }



        [Authorize]
        [HttpPost]
        public ActionResult GroupRemove(DeleteGroupModel model)
        {
            try
            {
                var repo = Repository;
                var group = GroupCompiledQueries.GetGroup(repo as Repository, model.GroupId);
                var user = CurrentUser;
                var relationship = RelationshipCompiledQueries.GetMemberOfRelationship(repo as Repository, user.Id,
                                                                                       group.Id);

                if(relationship != null)
                {
                    Repository.DeleteObject(relationship); 
                    Repository.SaveChanges();
                }

                return RedirectToAction("GroupOwnerList");
            }
            catch
            {
                return View(model);
            }
        }

        [Authorize]
        public ActionResult GroupMembers(Guid id)
        {
            var repo = Repository;
            var user = CurrentUser;
            var blockedFriends = RelationshipCompiledQueries.GetBlockedRelationships(repo as Repository, user.Id);                           // all users that are blocked
            var members = Repository.GetMembersOf(id).Where(usr => !blockedFriends.Any(
                bl => (bl.BaseSubject.Id == usr.Id || bl.BaseSubject2.Id == usr.Id)));
                

            var listMembers = new List<SuggestedMemebers>();
//            var memberPageable = members.GetPageable(page ?? 1, 50, (g => g.Created));
            foreach (var member in members)
            {
                var participantProfilePicturePath = Repository.GetProfilePicturePath(member.Id);
                var newParticipant = new SuggestedMemebers()
                {
                    FullName = member.FullName,
                    Id = member.Id,
                    ProfilePicturePath = participantProfilePicturePath,
                };
                listMembers.Add(newParticipant);
            }
            var model = new GroupMembersModel
            {
                GroupId = id,
                CurrentUserId = user.Id,
                Members = listMembers.ToArray()
//                Page = listMembers,
//                PageCount = memberPageable.PageCount,
//                PageIndex = memberPageable.PageIndex
            };
            return View(model);
        }


        [Authorize]
        public ActionResult InviteFriendsToGroup(Guid id)
        {
            var user = CurrentUser;

            var allFriends = Repository.GetFriendsOf(user.Id);
            var friendsLookupList = new List<FriendsLookupModels>();
            foreach (var friend in allFriends)
            {
                var newMember = new FriendsLookupModels()
                {
                    FirstName = friend.FirstName,
                    Fullname = friend.FullName,
                    LastName = friend.LastName,
                    Id = friend.Id,
                    ProfilePicturePath = Repository.GetProfilePicturePath(friend.Id),
                    Selected = false
                };
                friendsLookupList.Add(newMember);
            }
            var json = JsonHelper.Serialize(friendsLookupList);
            Session["allFriends"] = json;

            var model = new InviteGroupModel
                            {
                                GroupId = id,
                                CurrentUserId = user.Id
                            };
            return View(model);
        }

        [Authorize]
        [HttpPost]
        public ActionResult InviteFriendsToGroup(InviteGroupModel model)
        {

            if (model.UsersSelected == null)
            {
                return View(model);
            }
            var repo = Repository;
            //users that already got requested
            var usersAlreadyRequsted = UserCompiledQueries.UsersAlreadyRequested(repo as Repository, model.GroupId);
            //useres who were selected and not requested already
            var selectedUsers =
                Repository.AsQueryable<User>().Where(
                    u => model.UsersSelected.Contains(u.Id) && !usersAlreadyRequsted.Contains(u.Id));

            var group = GroupCompiledQueries.GetGroup(repo as Repository, model.GroupId);
            var currentUser = CurrentUser;
            foreach (var suggestedMemeberse in selectedUsers)
            {
                var relationship = new Relationship
                                        {
                                            Id = Guid.NewGuid(),
                                            PrivacyType = ObjectPrivacy.FriendsOnly,
                                            BaseSubject = suggestedMemeberse,
                                            BaseSubject2 = group,
                                            Created = DateTime.Now,
                                            RelationType = RelationshipType.MemberOf,
                                            Description = RelationshipType.MemberOfText,
                                            Status = RelationshipStatus.Requested,
                                            Type = ObjectType.Relationship,
                                            Name = RelationshipType.MemberOfText
                                        };
                Repository.AddObject(relationship);
                SendEmailConfirmGroupInvitation(relationship);

                //InvitesYour notification
                var newNotification = new Notification()
                {
                    Active = true,
                    BaseSubject = suggestedMemeberse,
                    Created = DateTime.Now,
                    Id = Guid.NewGuid(),
                    Type = BaseMessageType.Notification
                };
                var viewData3 = new
                {
                    BaseSubjectType = "group",
                    SubjectId = model.GroupId,
                    SubjectFullname = group.FullName,
                    InviterId = currentUser.Id,
                    InviterFullname = currentUser.FullName
                };

                var viewDictionary3 = viewData3.ToViewDataDictionary();
                newNotification.Content = ControlToString("~/Views/Notification/InvitesYou.cshtml", viewDictionary3);
                Repository.AddObject(newNotification);

            }
            Repository.SaveChanges();

            return Json(model);
        }


        [Authorize]
        public ActionResult ChangeAdmin(Guid id)
        {
            var memebers = Repository.GetMembersOf(id);
            var friendsLookupList = new List<FriendsLookupModels>();
            foreach (var memeber in memebers)
            {
                var newMember = new FriendsLookupModels()
                {
                    FirstName = memeber.FirstName,
                    Fullname = memeber.FullName,
                    LastName = memeber.LastName,
                    Id = memeber.Id,
                    ProfilePicturePath = Repository.GetProfilePicturePath(memeber.Id),
                    Selected = false
                };
                friendsLookupList.Add(newMember);
            }
            var json = JsonHelper.Serialize(friendsLookupList);
            Session["allMembers"] = json;

            var model = new ChangeAdminModel
            {
                EventId = id, // this is group id in this case
                CurrentUserId = CurrentUser.Id,
                SubjectId = id
            };

            return View(model);
        }


        [Authorize]
        [HttpPost]
        public ActionResult ChangeAdmin(Guid id, ChangeAdminModel model)
        {
            var repo = Repository;
            var group = GroupCompiledQueries.GetGroup(repo as Repository, id);
            var selectedMember = UserCompiledQueries.GetUser(repo as Repository, model.SelectedId);
            if(selectedMember != null)
            {
                //this is a temporary relationship till user doesnt accept it we will change his previous relationship to admin and we will delete this one
                var relationship = new Relationship
                {
                    Id = Guid.NewGuid(),
                    PrivacyType = ObjectPrivacy.FriendsOnly,
                    BaseSubject = selectedMember,
                    BaseSubject2 = group,
                    Created = DateTime.Now,
                    RelationType = RelationshipType.AdministratorOf,
                    Description = RelationshipType.AdministratorOfText,
                    Status = RelationshipStatus.Requested,
                    Type = ObjectType.Relationship,
                    Name = RelationshipType.AdministratorOfText
                };
                Repository.AddObject(relationship);
                Repository.SaveChanges();

                SendEmailConfirmAdminInvitation(relationship);

                return Json(model);
            }
            return View(model);
        }


        #region Subject members

        public override ActionResult ConfirmRelationshipNotification(Relationship relationship)
        {
            var model = new NotifyModel
                            {
                                Title = "Invite request",
                                Header = "Confirm group invite",
                                Body = "Group invite successfully confirmed.",
                                NotificationType = NotificationType.Notification
                            };

            return RedirectToAction("Notify", "Home", model);
        }

        public override ActionResult PostponeRelationshipNotification(Relationship relationship)
        {
            var model = new NotifyModel
                            {
                                Title = "Invite request",
                                Header = "Postpone group invite",
                                Body = "Group invite successfully postponed.",
                                NotificationType = NotificationType.Notification
                            };

            return RedirectToAction("Notify", "Home", model);
        }

        public override ActionResult PostponeFailedRelationshipNotification(Relationship relationship)
        {
            var model = new NotifyModel
                            {
                                Title = "Invite request",
                                Header = "Postpone group invite",
                                Body =
                                    "Invitation to group request couldn't be postponed, because the invitation was already confrirmed.",
                                NotificationType = NotificationType.Notification
                            };

            return RedirectToAction("Notify", "Home", model);
        }

        #endregion

        #region Email sending


        public bool SendEmailConfirmAdminInvitation(Relationship rel)
        {
            var user = CurrentUser;
            var repo = Repository;
            var relSubject = UserCompiledQueries.GetSubjectFromRelationship(repo as Repository, rel.Id);
            var relSubject2 = UserCompiledQueries.GetSubject2FromRelationship(repo as Repository, rel.Id);
            var viewData = new
            {
                XSettings.SiteName,
                FriendName = relSubject.FullName,
                YourName = user.FullName,
                EventName = ((Group)relSubject2).Name,
                RelationshipId = rel.Id,
                ConfirmFriendshipUrl =
                    new Uri(HttpContext.Request.Url,
                            Url.Action("ConfirmAdminRelationship", "Group", new { id = rel.Id })).ToString(),
                PostponeFriendshipUrl =
                    new Uri(HttpContext.Request.Url,
                            Url.Action("PostponeRelationship", "Group", new { id = rel.Id })).ToString(),
                XSettings.SiteUrl,
                YourProfileUrl =
                    new Uri(HttpContext.Request.Url,
                            Url.Action("ProfileView", "Profile", new { id = user.Id })).ToString(),
                EventDetailsUrl =
                   new Uri(HttpContext.Request.Url,
                           Url.Action("GroupDetails", "Group", new { id = relSubject2.Id })).ToString()
            };
            var viewDictionary = viewData.ToViewDataDictionary();

            return SendTemplatedEmail(new List<string> { ((User)relSubject).Email }, String.Format("{0} site: Administrator confirmation is required", XSettings.SiteName),
                                                   "~/Views/Email/ConfirmAdminInvitation.cshtml", viewDictionary);
        }


        public bool SendEmailConfirmGroupInvitation(Relationship rel)
        {
            var user = CurrentUser;
            var repo = Repository;
            var relSubject = UserCompiledQueries.GetSubjectFromRelationship(repo as Repository, rel.Id);
            var relSubject2 = UserCompiledQueries.GetSubject2FromRelationship(repo as Repository, rel.Id);
            var viewData = new
                               {
                                   XSettings.SiteName,
                                   FriendName = relSubject.FullName,
                                   YourName = user.FullName,
                                   GroupName = relSubject2.FullName,
                                   RelationshipId = rel.Id,
                                   ConfirmFriendshipUrl =
                                       new Uri(HttpContext.Request.Url,
                                               Url.Action("ConfirmRelationship", "Group", new {id = rel.Id})).ToString(),
                                   PostponeFriendshipUrl =
                                       new Uri(HttpContext.Request.Url,
                                               Url.Action("PostponeRelationship", "Group", new {id = rel.Id})).ToString(),
                                   XSettings.SiteUrl,
                                   YourProfileUrl =
                                       new Uri(HttpContext.Request.Url,
                                               Url.Action("ProfileView", "Profile", new { id = user.Id })).ToString(),
                                   GroupDetailsUrl =
                                      new Uri(HttpContext.Request.Url,
                                              Url.Action("GroupDetails", "Group", new { id = rel.BaseSubject2.Id })).ToString()
                               };
            var viewDictionary = viewData.ToViewDataDictionary();

            return SendTemplatedEmail(new List<string> { ((User)relSubject).Email },
                                                   String.Format("{0} site: Membership confirmation is required", XSettings.SiteName),
                                                   "~/Views/Email/ConfirmGroupInvitation.cshtml", viewDictionary);
        }

        #endregion

        #region Extra functions


        public void DeleteAllBaseObjects(Guid groupId)
        {
            var repo = Repository;
            //find all posts from event
            var allPosts = PostCompiledQueries.GetAllPostsGeneral(repo as Repository, groupId);

            // if (Event->Post->BaseObject->SomeUser) and if (Event.delete->Post.delete !-> BaseObject->SomeUser)
            //BaseObject will be not deleted and it will not have post so we must delete it manually all BaseObjects connected with Event->Posts


            var allStatuses = Repository.AsQueryable<Status>().Where(st => allPosts.Any(pst => pst.BaseObject.Id == st.Id)).ToArray();
            foreach (var status in allStatuses)
            {
                Repository.DeleteObject(status);
            }
            var allNotes = Repository.AsQueryable<Note>().Where(no => allPosts.Any(pst => pst.BaseObject.Id == no.Id)).ToArray();
            foreach (var note in allNotes)
            {
                Repository.DeleteObject(note);
            }
            var allLinks = Repository.AsQueryable<Link>().Where(no => allPosts.Any(pst => pst.BaseObject.Id == no.Id)).ToArray();
            foreach (var link in allLinks)
            {
                Repository.DeleteObject(link);
            }
            var album = AlbumCompiledQueries.GetAlbumBySubjectId(repo as Repository, groupId);
            var medias = MediaCompiledQueries.GetMediasOf(repo as Repository, album.Id);
            foreach (var media in medias)
            {
                Repository.DeleteObject(media);
            }
            //Repository.SaveChanges();

            //foreach (var post in allPosts)
            //{
            //    Repository.DeleteObject(post);
            //}

            Repository.DeleteObject(album);
            Repository.SaveChanges();
            
        }


        public void CreateNotification(Guid groupId, string groupFullname, Dictionary<string, string> values)
        {
            //create a notifications
            var members = Repository.GetMembersOf(groupId).ToList();
            var admin = Repository.GetAdminOf(groupId);
            members.Add(admin);
            foreach (var member in members)
            {
                foreach (var value in values)
                {
                    //GroupEventPageChange notification
                    var newNotification = new Notification()
                    {
                        Active = true,
                        BaseSubject = member,
                        Created = DateTime.Now,
                        Id = Guid.NewGuid(),
                        Type = BaseMessageType.Notification
                    };
                    var viewData3 = new
                    {
                        BaseSubjectType = "group",
                        SubjectId = groupId,
                        SubjectFullname = groupFullname,
                        Value = value.Key,
                        Value2 = value.Value
                    };

                    var viewDictionary3 = viewData3.ToViewDataDictionary();
                    newNotification.Content = ControlToString("~/Views/Notification/GroupEventPageChange.cshtml", viewDictionary3);
                    Repository.AddObject(newNotification);
                }

            }
            Repository.SaveChanges();
        }

        #endregion
    }
}